import { createSlice,createAsyncThunk } from "@reduxjs/toolkit";
import {getOne} from '../../services/order';

export const fetchOrder = createAsyncThunk('order/fetchOrder',async (id) => {
    let {data} = await getOne(id);
    console.log(data);
    return data;
});

const orderSlice = createSlice({
    name: 'order',
    initialState:{
        isModalVisible:false,
        order:{},
        updateVisible:false,
    },
    reducers:{
        setIsModalVisible(state,action){
            state.isModalVisible =action.payload;
        },
        setUpdateVisible(state,action){
            state.updateVisible =action.payload;
        }
    },
    extraReducers(builder) {
        builder.addCase(fetchOrder.fulfilled, (state, action) => {
            state.order = action.payload;
        })
    }
})

export const {setIsModalVisible,setUpdateVisible} = orderSlice.actions;
export default orderSlice.reducer;